<!DOCTYPE html>
<script src="../../resources/ahem.js"></script>
<div id="target" style="
    outline: dashed lightblue;
    height: 150px;
    padding: 25px;
    font: 20px Ahem;
    writing-mode: vertical-rl;
">Lorem ipsum dolor sit amet</div>
<pre id="log"></pre>
<script>
    if (window.testRunner && window.internals) {
        testRunner.dumpAsText();
        internals.settings.setEditingBehavior("mac");
    }        

    function log(message)
    {
        document.getElementById("log").appendChild(document.createTextNode(message + "\n"));
    }

    function test(y, x, expectedOffset)
    {
        var actualOffset = document.caretRangeFromPoint(8 + x, 8 + y).startOffset;
        if (actualOffset === expectedOffset)
            log("PASS: offset at (" + y + "," + x + ") was " + actualOffset + ".");
        else
            log("FAIL: offset at (" + y + "," + x + ") was " + actualOffset + ". Expected " + expectedOffset + ".");
    }

    test(100, 105, 4);
    test(160, 105, 5);
    test(100, 104, 10);
    test(160, 104, 11);
    test(60, 26, 24);
    test(160, 26, 26);
    test(60, 25, 24);
    test(160, 25, 26);
    test(60, 24, 26);
    test(160, 24, 26);
</script>
